package com.bw.module_service.adapter

import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.widget.TextView
import com.bw.module_service.R
import com.bw.module_service.model.ParkSpaceModelItem
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class ParkSpaceAdapter:BaseQuickAdapter<ParkSpaceModelItem,BaseViewHolder>(R.layout.item_parkspace) {
    override fun convert(holder: BaseViewHolder, item: ParkSpaceModelItem) {
        holder.setText(R.id.parkspace_num,item.spaceNumber)
        holder.setText(R.id.parkspace_address,"所属区域:"+item.areaName)
        holder.setText(R.id.parkspace_type,"车位类型:"+item.spaceType)
        holder.setText(R.id.parkspace_owner,"使用人:"+item.userName)
        holder.setText(R.id.parkspacecar_num,"车牌号:"+item.licensePlate)
        holder.setText(R.id.parkspace_status,item.spaceStatus)

//        if(item.spaceStatus == "空闲"){
//            holder.getView<TextView>(R.id.parkspace_status).setBackgroundColor(Color.parseColor("#F0FDF4"))
//            holder.getView<TextView>(R.id.parkspace_status).setTextColor(Color.parseColor("#46B770"))
//        }else if(item.spaceStatus == "已占用"){
//            holder.getView<TextView>(R.id.parkspace_status).setBackgroundColor(Color.parseColor("#EFF6FF"))
//            holder.getView<TextView>(R.id.parkspace_status).setTextColor(Color.parseColor("#4F82EF"))
//        }else if(item.spaceStatus == "维修中"){
//            holder.getView<TextView>(R.id.parkspace_status).setBackgroundColor(Color.parseColor("#fefce8"))
//            holder.getView<TextView>(R.id.parkspace_status).setTextColor(Color.parseColor("#CB8C08"))
//        }

        val statusView = holder.getView<TextView>(R.id.parkspace_status)
        // 获取原始背景作为 GradientDrawable
        val background = statusView.background as? GradientDrawable

        when (item.spaceStatus) {
            "空闲" -> {
                background?.setColor(Color.parseColor("#F0FDF4"))
                statusView.setTextColor(Color.parseColor("#46B770"))
            }
            "已占用" -> {
                background?.setColor(Color.parseColor("#EFF6FF"))
                statusView.setTextColor(Color.parseColor("#4F82EF"))
            }
            "维修中" -> {
                background?.setColor(Color.parseColor("#fefce8"))
                statusView.setTextColor(Color.parseColor("#CB8C08"))
            }
        }
        statusView.background = background // 重新设置带颜色的背景

    }



}